#include <bits/stdc++.h>
using namespace std;
const int N=200050;
typedef long long ll;
typedef long double ld;
int n;
ll a[N],sum[N];
map<int,int> cnt;
int main(void){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    ld ans=0;
    for(int i=1;i<=n;i++){
        //printf("%d\n",i);
        ans+=(ld)a[i]*(i-1)-sum[i-1];
        //printf("** %lld\n",a[i]*(i-1)-sum[i-1]);
        ans-=cnt[a[i]-1];
        ans+=cnt[a[i]+1];
        cnt[a[i]]++;
        //printf("--%lld--\n",ans);
    }
    printf("%.0Lf\n",ans);
    return 0;
}